;;; +fonts.el --- fonts config -*- lexical-binding: t -*-

;;; Commentary:

;;; Code:

(defun font-installed-p (font-name)
  "Check if font with FONT-NAME is available."
  (find-font (font-spec :name font-name)))

(when (display-graphic-p)

  ;; 因其字符集較為分散，先設置emoji（unicode），再設置默認字體。
  (dolist (font '("Noto Color Emoji" "OpenSansEmoji"
                  "Segoe UI Emoji" "EmojiOne Color"
                  "Standard Symbols L" "Symbola" "Symbol"))
    (when (font-installed-p font)
      (set-fontset-font t 'unicode ;; '(#xF600 . #xF64F)
                        font nil 'prepend)))

  ;; default (latin letters)
  (cl-loop for font in '("SF Mono" "Cascadia Code" "Source Code Pro"
                         "Monaco" "Dejavu Sans Mono" "Consolas")
           when (font-installed-p font) return
           (set-face-attribute 'default nil
                               :font (font-spec :family font :size 18)))

  ;; CJK characters
  ;; can use charset name to instead '(#x4e00 . #x9fff) or '(#x3000 . #x9fff)
  ;; which contain CJK-symbols-&-punctuation
  ;; 毋需單獨設置字體大小(font-spec :size)，否則中文字號不能自動調整(scale)。
  (setq use-default-font-for-symbols nil)
  (cl-loop for font in '("TsangerJinKai03" "仓耳今楷03" ;; 倉耳今楷
                         "LXGW WenKai Mono" "霞鹜文楷等宽" ;; 霞鶩文楷
                         "思源黑体 CN" "Source Han Sans CN"
                         "微软雅黑 CN" "Microsoft Yahei UI" "Microsoft Yahei"
                         "Noto Sans CJK SC")
           when (font-installed-p font) return
           (dolist (charset '(kana han symbol cjk-misc bopomofo))
             (set-fontset-font
              (frame-parameter nil 'font) charset
              (font-spec :family font) nil 'append)))

  ;; CJK-unified-ideographs-extension-B 中日韓統一表意文字擴展區B
  (dolist (font '("HanaMinB" "SimSun-ExtB"))
    (when (font-installed-p font)
      (set-fontset-font t '(#x20000 . #x2A6DF)
                        font nil 'append))))

(provide '+fonts)

;;; +fonts.el ends here
